package servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pojo.User;

import com.sun.xml.internal.bind.v2.model.core.ID;

import factory.UserManagerFactory;
import service.UserManager;



public class loginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
   private static UserManager userManager=UserManagerFactory.getUserManagerInstance();
    public loginServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String name=req.getParameter("name");
		String password=req.getParameter("password");
		User u=userManager.login(name, password);
		if(u!=null){
			req.getSession().setAttribute("u", u);
			req.getRequestDispatcher("/findAll").forward(req, resp);
		}
		else {
			resp.sendRedirect("login.html");
		}
	}

}
